package com.sgu6.sgu6_machine.db;

import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;

import com.sgu6.sgu6_machine.db.converter.GoodsSimpleConverter;
import java.util.List;

import com.sgu6.sgu6_machine.dto.ListGoodsSimpleDto;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "LIST_GOODS_SIMPLE_DTO".
*/
public class ListGoodsSimpleDtoDao extends AbstractDao<ListGoodsSimpleDto, String> {

    public static final String TABLENAME = "LIST_GOODS_SIMPLE_DTO";

    /**
     * Properties of entity ListGoodsSimpleDto.<br/>
     * Can be used for QueryBuilder and for referencing column names.
    */
    public static class Properties {
        public final static Property VarietyName = new Property(0, String.class, "varietyName", false, "VARIETY_NAME");
        public final static Property BarnId = new Property(1, String.class, "barnId", true, "BARN_ID");
        public final static Property GoodsSortDtoList = new Property(2, String.class, "goodsSortDtoList", false, "GOODS_SORT_DTO_LIST");
    };

    private final GoodsSimpleConverter goodsSortDtoListConverter = new GoodsSimpleConverter();

    public ListGoodsSimpleDtoDao(DaoConfig config) {
        super(config);
    }
    
    public ListGoodsSimpleDtoDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"LIST_GOODS_SIMPLE_DTO\" (" + //
                "\"VARIETY_NAME\" TEXT," + // 0: varietyName
                "\"BARN_ID\" TEXT PRIMARY KEY NOT NULL ," + // 1: barnId
                "\"GOODS_SORT_DTO_LIST\" TEXT);"); // 2: goodsSortDtoList
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"LIST_GOODS_SIMPLE_DTO\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, ListGoodsSimpleDto entity) {
        stmt.clearBindings();
 
        String varietyName = entity.getVarietyName();
        if (varietyName != null) {
            stmt.bindString(1, varietyName);
        }
 
        String barnId = entity.getBarnId();
        if (barnId != null) {
            stmt.bindString(2, barnId);
        }
 
        List goodsSortDtoList = entity.getGoodsSortDtoList();
        if (goodsSortDtoList != null) {
            stmt.bindString(3, goodsSortDtoListConverter.convertToDatabaseValue(goodsSortDtoList));
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, ListGoodsSimpleDto entity) {
        stmt.clearBindings();
 
        String varietyName = entity.getVarietyName();
        if (varietyName != null) {
            stmt.bindString(1, varietyName);
        }
 
        String barnId = entity.getBarnId();
        if (barnId != null) {
            stmt.bindString(2, barnId);
        }
 
        List goodsSortDtoList = entity.getGoodsSortDtoList();
        if (goodsSortDtoList != null) {
            stmt.bindString(3, goodsSortDtoListConverter.convertToDatabaseValue(goodsSortDtoList));
        }
    }

    @Override
    public String readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1);
    }    

    @Override
    public ListGoodsSimpleDto readEntity(Cursor cursor, int offset) {
        ListGoodsSimpleDto entity = new ListGoodsSimpleDto( //
            cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // varietyName
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // barnId
            cursor.isNull(offset + 2) ? null : goodsSortDtoListConverter.convertToEntityProperty(cursor.getString(offset + 2)) // goodsSortDtoList
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, ListGoodsSimpleDto entity, int offset) {
        entity.setVarietyName(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
        entity.setBarnId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setGoodsSortDtoList(cursor.isNull(offset + 2) ? null : goodsSortDtoListConverter.convertToEntityProperty(cursor.getString(offset + 2)));
     }
    
    @Override
    protected final String updateKeyAfterInsert(ListGoodsSimpleDto entity, long rowId) {
        return entity.getBarnId();
    }
    
    @Override
    public String getKey(ListGoodsSimpleDto entity) {
        if(entity != null) {
            return entity.getBarnId();
        } else {
            return null;
        }
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
}
